//
//  HMMainViewController.swift
//  CZBKWB31
//
//  Created by Linkon Y on 16/8/9.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class HMMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        //实例化自定义tabbar
        let tabBar = HMTabBar()
    
        //设置代理
        tabBar.HMDegelate = self
       
        //通过kvc给只读属性赋值
        setValue(tabBar, forKey: "tabBar")
        
        //首页
        addChildViewController(HMHomeViewController(), imageName: "tabbar_home", title: "首页")
        //消息
        addChildViewController(HMMessageViewController(), imageName: "tabbar_message_center", title: "消息")
        //发现
        addChildViewController(HMDiscoverViewController(), imageName: "tabbar_discover", title: "发现")
        //我的
        addChildViewController(HMProfileViewController(), imageName: "tabbar_profile", title: "我的")
       
        }
    /**
     添加子控制器
     
     - parameter Vc:        控制器
     - parameter imageName: 图片名称
     - parameter title:     控制器名称
     */
    
    func addChildViewController(Vc: UIViewController , imageName: String , title: String) {
        
        //设置首页
//        Vc.navigationItem.title = title
//        Vc.tabBarItem.title = title
        Vc.title = title
        
        //设置点击字体颜色
        Vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: UIControlState.Selected)
        //设置图片
        Vc.tabBarItem.image = UIImage(named: imageName)
        //另外一种设置点击颜色的方式
        Vc.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        //添加自控制器
        addChildViewController(UINavigationController(rootViewController: Vc))
    }
}


extension HMMainViewController:HMTabBarDelegate{
    func tabBarButtonClick() {
        //判断是否登录
        if !HMUserAccountViewModel.sharedTools.isLogin{
            print("请登录")
             return
        
        }
        
        self.presentViewController(UINavigationController(rootViewController: HMComposeViewController()), animated: true, completion: nil)
        
        
    }
}
